package day07_Array;
import java.util.ArrayList;
/*
创建Student类
属性要有clazz
ArrarList中添加多个学生
求每个班级中有多少学生
输出结果例如：一班：30
 */
public class Demo10班级学生 {
    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<Student>();
        Student student1 = new Student("zs1",18,"一班");
        Student student2 = new Student("zs2",18,"一班");
        Student student3 = new Student("zs3",18,"二班");
        Student student4 = new Student("zs4",18,"一班");
        Student student5 = new Student("zs5",18,"一班");
        Student student6 = new Student("zs6",18,"三班");
        Student student7 = new Student("zs7",18,"一班");
        Student student8 = new Student("zs8",18,"一班");
        Student student9 = new Student("zs9",18,"二班");
        Student student10 = new Student("zs10",18,"一班");
        Student student11= new Student("zs11",18,"一班");
        Student student12= new Student("zs12",18,"三班");
        Student student13= new Student("zs13",18,"一班");
        Student student14= new Student("zs14",18,"二班");
        Student student15= new Student("zs15",18,"一班");
        students.add(student1);
        students.add(student2);
        students.add(student3);
        students.add(student4);
        students.add(student5);
        students.add(student6);
        students.add(student7);
        students.add(student8);
        students.add(student9);
        students.add(student10);
        students.add(student11);
        students.add(student12);
        students.add(student13);
        students.add(student14);
        students.add(student15);
        ArrayList<String> clazz = new ArrayList<>();
        //用于存储班级的分类
        for (int i = 0; i <students.size() ; i++) {
            if (!clazz.contains(students.get(i).getClazz())){
                clazz.add(students.get(i).getClazz());
            }
        }
        System.out.println(clazz);
        //匹配然后累加输出
        for (int i = 0; i <clazz.size() ; i++) {
            int sum=0;
            for (int j = 0; j <students.size() ; j++) {
                if (clazz.get(i).equals(students.get(j).getClazz())){
                    sum++;
                }
            }
            System.out.println(clazz.get(i)+":"+sum);
        }
    }
}
